#include "gde0213b1.h"
#include "rtconfig.h"
#include "rtdevice.h"
#include "appconfig.h"

#define xDot 128    //为了能除8
#define yDot 250

unsigned char GDOControl[]={0x01,(yDot-1)%256,(yDot-1)/256,0x00}; //for 2.13inch
unsigned char softstart[]={0x0c,0xd7,0xd6,0x9d};
unsigned char Rambypass[] = {0x21,0x8f};		// Display update
unsigned char MAsequency[] = {0x22,0xf0}; 	// clock 
unsigned char GDVol[] = {0x03,0xea};	// Gate voltage +15V/-15V
unsigned char SDVol[] = {0x04,0x0a};	// Source voltage +15V/-15V
unsigned char VCOMVol[] = {0x2c,0x55};	// VCOM 7c
unsigned char BOOSTERFB[] = {0xf0,0x1f};	// Source voltage +15V/-15V
unsigned char DummyLine[] = {0x3a,0x1a};	// 4 dummy line per gate
unsigned char Gatetime[] = {0x3b,0x08}; // 2us per line
unsigned char BorderWavefrom[] = {0x3c,0x33}; // Border
unsigned char RamDataEntryMode[] = {0x11,0x01}; // Ram data entry mode

const unsigned char LUTDefault_full[]={
0x32,	// command

0x22,
0x55,
0xAA,
0x55,
0xAA,
0x55,
0xAA,
0x11,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x1E,
0x1E,
0x1E,
0x1E,
0x1E,
0x1E,
0x1E,
0x1E,
0x01,
0x00,
0x00,
0x00,
0x00,


};

const unsigned char LUTDefault_part[]={
0x32,	// command

0x18,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x0F,
0x01,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
};



void SPI_Write(unsigned char value)                                    
{                                                           
    unsigned char i;

    for(i=0; i<8; i++)   
    {
        EPD_W21_CLK_0;
        if(value & 0x80)
        	EPD_W21_MOSI_1;
        else
        	EPD_W21_MOSI_0;		
        value = (value << 1); 
        EPD_W21_CLK_1;  
    }
}

void driver_delay_xms(unsigned long xms)	
{	
    unsigned long i = 0 , j=0;

    for(j=0;j<xms;j++)
	{
        for(i=0; i<256*40; i++);
    }
}


static unsigned char ReadBusy(void)
{
  unsigned long i=0;

  
  for(i=0;i<400;i++)
  {
      if(isEPD_W21_BUSY==EPD_W21_BUSY_LEVEL) {
      return 1;
      }
	  rt_thread_delay(5);
  }
  return 0;
}

static void EPD_W21_WriteCMD(unsigned char command)
{
	EPD_W21_CS_0;                   
	EPD_W21_DC_0;		// command write
	SPI_Write(command);
	EPD_W21_CS_1;
}

//static void EPD_W21_WriteDATA(unsigned char command)
//{
//    EPD_W21_CS_0;                   
//	EPD_W21_DC_1;		// command write
//	SPI_Write(command);
//	EPD_W21_CS_1;
//}
	
static void EPD_W21_WriteCMD_p1(unsigned char command,unsigned char para)
{
	//while(isEPD_W21_BUSY == 1);	// wait
	ReadBusy();	

	EPD_W21_CS_0;                   
	EPD_W21_DC_0;		// command write
	SPI_Write(command);
	EPD_W21_DC_1;		// command write
	SPI_Write(para);
	EPD_W21_CS_1;
}

//static void EPD_W21_WriteCMD_p2(unsigned char command,unsigned char para1,unsigned char para2)
//{
//	while(isEPD_W21_BUSY == 1);	// wait	
//
//    EPD_W21_CS_0;                   
//	EPD_W21_DC_0;		// command write
//	SPI_Write(command);
//	EPD_W21_DC_1;		// command write
//	SPI_Write(para1);
//	SPI_Write(para2);
//	EPD_W21_CS_1;
//} 
/*********************************************
¹¦ÄÜ£ºµÚÒ»¸ö×Ö½ÚÐ´ÈëµÄÊÇÃüÁîÖµ£¬Ê£ÓàµÄÊÇ²ÎÊý£¬
ÔÚÅäÖÃ½×¶ÎÊ¹ÓÃ

*********************************************/
static void EPD_W21_Write(unsigned char *value, unsigned char datalen)
{
	unsigned char i = 0;
	unsigned char *ptemp;

	ptemp = value;


	EPD_W21_CS_0;                   	
	EPD_W21_DC_0;		// command write
	
	SPI_Write(*ptemp);
	ptemp++;

	EPD_W21_DC_1;		// data write
	
	for(i= 0;i<datalen-1;i++)	// sub the command
	{
		SPI_Write(*ptemp);
		ptemp++;
	}

	EPD_W21_CS_1;

}
/*********************************************
¹¦ÄÜ£ºÐ´ÏÔÊ¾buffer
²ÎÊý£º 	XSize  x·½ÏòÊýÁ¿  128µã·½Ïò£¬µ÷ÕûÎª8µÄÕûÊý±¶
		YSize  y·½ÏòÊýÁ¿	 	   	
		Dispbuff ÏÔÊ¾Êý¾Ý±£´æÎ»ÖÃ¡£ ÒªÇóÊý¾ÝµÄÅÅÁÐ·½Ê½±ØÐëÕýÈ·
*********************************************/
static void EPD_W21_WriteDispRam(unsigned char XSize,unsigned int YSize,
							unsigned char *Dispbuff,unsigned char flag)
{
	int i = 0,j = 0;

	if(XSize%8 != 0)
	{
		XSize = XSize+(8-XSize%8);
	}
	XSize = XSize/8;

	//while(isEPD_W21_BUSY == 1);	//wait
	ReadBusy();		
	
    EPD_W21_CS_0;                   
	EPD_W21_DC_0;		//command write
	SPI_Write(0x24);
	
	EPD_W21_DC_1;		//data write
	for(i=0;i<YSize;i++)
	{
		for(j=0;j<XSize;j++)
		{
			if(flag == 1)
			{
				SPI_Write(~(*Dispbuff));
			}
			else
			{
				SPI_Write(*Dispbuff);
			}
			
			Dispbuff++;
		}
	}
	
	EPD_W21_CS_1;
}
/*********************************************
¹¦ÄÜ£º  Ð´ÏÔÊ¾buffer ÓÃÀ´½«Ä³Ò»¸öÇøÓòÐ´ÈëÏàÍ¬µÄÏÔÊ¾ÄÚÈÝ¡£
²ÎÊý£º 	XSize  x·½ÏòÊýÁ¿  128µã·½Ïò£¬µ÷ÕûÎª8µÄÕûÊý±¶
		YSize  y·½ÏòÊýÁ¿	 	   	
		dispdata ÏÔÊ¾Êý¾Ý¡£
*********************************************/
static void EPD_W21_WriteDispRamMono(unsigned char XSize,unsigned int YSize,
							unsigned char dispdata)
{
	int i = 0,j = 0;

	if(XSize%8 != 0)
	{
		XSize = XSize+(8-XSize%8);
	}
	XSize = XSize/8;
	//while(isEPD_W21_BUSY == 1);	// wait	
	ReadBusy();	

    EPD_W21_CS_0;                   
	EPD_W21_DC_0;		// command write
	SPI_Write(0x24);
	
	EPD_W21_DC_1;		// data write
	for(i=0;i<YSize;i++)
	{
		for(j=0;j<XSize;j++)
		{
		 SPI_Write(dispdata);
		}
	}
	
	EPD_W21_CS_1;
}

static void EPD_W21_POWERON(void)
{
	EPD_W21_WriteCMD_p1(0x22,0xc0);
	EPD_W21_WriteCMD(0x20);
	//EPD_W21_WriteCMD(0xff);
}
void EPD_W21_POWEROFF(void) //POWER OFF
{  	EPD_W21_WriteCMD_p1(0x22,0xc3);
	EPD_W21_WriteCMD(0x20);
//	EPD_W21_WriteCMD(0xff);
}
void EPD_W21_SLEEP(void) //SLEEP MODE
{
		EPD_W21_WriteCMD_p1(0x10,0x01);
}

static void EPD_W21_SetRamArea(unsigned char Xstart,unsigned char Xend,
						unsigned char Ystart,unsigned char Ystart1,unsigned char Yend,unsigned char Yend1)
{
    unsigned char RamAreaX[3];	// X start and end
	unsigned char RamAreaY[5]; 	// Y start and end
	RamAreaX[0] = 0x44;	// command
	RamAreaX[1] = Xstart;
	RamAreaX[2] = Xend;
	RamAreaY[0] = 0x45;	// command
	RamAreaY[1] = Ystart;
	RamAreaY[2] = Ystart1;
	RamAreaY[3] = Yend;
    RamAreaY[4] = Yend1;
	EPD_W21_Write(RamAreaX, sizeof(RamAreaX));
	EPD_W21_Write(RamAreaY, sizeof(RamAreaY));
}
static void EPD_W21_SetRamPointer(unsigned char addrX,unsigned char addrY,unsigned char addrY1)
{
    unsigned char RamPointerX[2];	// default (0,0)
	unsigned char RamPointerY[3]; 	
	RamPointerX[0] = 0x4e;
	RamPointerX[1] = addrX;
	RamPointerY[0] = 0x4f;
	RamPointerY[1] = addrY;
	RamPointerY[2] = addrY1;
	
	EPD_W21_Write(RamPointerX, sizeof(RamPointerX));
	EPD_W21_Write(RamPointerY, sizeof(RamPointerY));
}
static void part_display(unsigned char RAM_XST,unsigned char RAM_XEND,unsigned char RAM_YST,unsigned char RAM_YST1,unsigned char RAM_YEND,unsigned char RAM_YEND1)
{    
	EPD_W21_SetRamArea(RAM_XST,RAM_XEND,RAM_YST,RAM_YST1,RAM_YEND,RAM_YEND1);  	/*set w h*/
    EPD_W21_SetRamPointer (RAM_XST,RAM_YST,RAM_YST1);		    /*set orginal*/
}
//static void EPD_W21_UpdataDisplay(unsigned char *imgbuff,unsigned char xram,unsigned int yram)
//{
//	EPD_W21_WriteDispRam(xram, yram, imgbuff);
////	EPD_W21_Update();
//}

//=========================functions============================

//-------------------------------------------------------
//Func	: void EPD_W21_DispInit(void)
//Desc	: display parameters initinal
//Input	: none
//Output: none
//Return: none
//Author: 
//Date	: 2011/12/24
//-------------------------------------------------------
static void EPD_W21_DispInit(void)
{

//	EPD_W21_Write(softstart, sizeof(softstart));	// X decrease, Y decrease
//
//	EPD_W21_Write(GDOControl, sizeof(GDOControl));	// Pannel configuration, Gate selection
//
//	EPD_W21_Write(Rambypass, sizeof(Rambypass));	// Rambypass
//
//	EPD_W21_Write(MAsequency, sizeof(MAsequency));	// MAsequency
//
//	EPD_W21_Write(GDVol, sizeof(GDVol));		    // GDVol setting
//
//	EPD_W21_Write(SDVol, sizeof(SDVol));		    // SDVol setting
//
//	EPD_W21_Write(VCOMVol, sizeof(VCOMVol));		// VCOM setting
//
//	EPD_W21_Write(DummyLine, sizeof(DummyLine));	// dummy line per gate
//	
//	EPD_W21_Write(Gatetime, sizeof(Gatetime));		// Gage time setting
//	
//	EPD_W21_Write(RamDataEntryMode, sizeof(RamDataEntryMode));	// X increase, Y decrease


	EPD_W21_Write(GDOControl, sizeof(GDOControl));	// Pannel configuration, Gate selection	
  EPD_W21_Write(softstart, sizeof(softstart));	// X decrease, Y decrease
	

	//EPD_W21_Write(Rambypass, sizeof(Rambypass));	// RAM bypass setting
  //EPD_W21_Write(MAsequency, sizeof(MAsequency));	// clock enable
	//EPD_W21_Write(GDVol, sizeof(GDVol));			// Gate voltage setting
	//EPD_W21_Write(SDVol, sizeof(SDVol));			// Source voltage setting
	EPD_W21_Write(VCOMVol, sizeof(VCOMVol));		// VCOM setting

	//EPD_W21_Write(BOOSTERFB, sizeof(BOOSTERFB));	// Hi-V feedback selection
	EPD_W21_Write(DummyLine, sizeof(DummyLine));	// dummy line per gate
	
	EPD_W21_Write(Gatetime, sizeof(Gatetime));		// Gage time setting

	EPD_W21_Write(RamDataEntryMode, sizeof(RamDataEntryMode));	// X increase, Y decrease
	
	EPD_W21_SetRamArea(0x00,(xDot-1)/8,(yDot-1)%256,(yDot-1)/256,0x00,0x00);	// X-source area,Y-gage area
  EPD_W21_SetRamPointer(0x00,(yDot-1)%256,(yDot-1)/256);	// set ram

}
void epd_power_pin(rt_uint8_t value)
{
	static rt_uint8_t flag = 0;
	if(flag == 0)
	{
		 GPIO_InitTypeDef GPIO_InitStructure = {0};
		
		RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
		GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
		GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
		GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
		GPIO_Init(GPIOB, &GPIO_InitStructure);
	}

	if(value==0)
	{
		GPIO_ResetBits(GPIOB, GPIO_Pin_12);
	}
	else
	{
		GPIO_SetBits(GPIOB, GPIO_Pin_12);
	}
}

static void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure = {0};

	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_11;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
	GPIO_Init(GPIOA, &GPIO_InitStructure);
	//GPIO_ResetBits(GPIOA,GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_11);
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
	GPIO_Init(GPIOA,&GPIO_InitStructure);
	//epd_power_pin(0);
}


static void EPD_W21_Init(void)
{
	GPIO_Configuration();
	EPD_W21_BS_0;		// 4 wire spi mode selected

	EPD_W21_RST_0;		// Module reset
	rt_thread_delay(1);
	EPD_W21_RST_1;
	rt_thread_delay(1);

	EPD_W21_DispInit();		// pannel configure
}

//-------------------------------------------------------
//Func	: EPD_W21_EnableChargepump
//Desc	: 
//Input	:
//Output: 
//Return: 
//Author: 
//Date	: 2011/12/24
//-------------------------------------------------------
//static void EPD_W21_EnableChargepump(void)
//{
//	EPD_W21_WriteCMD_p1(0xf0,0x8f);
//	EPD_W21_WriteCMD_p1(0x22,0xc0);
//	EPD_W21_WriteCMD(0x20);
//	EPD_W21_WriteCMD(0xff);
//}

//-------------------------------------------------------
//Func	: EPD_W21_DisableChargepump
//Desc	: 
//Input	:
//Output: 
//Return: 
//Author: 
//Date	: 2011/12/24
//-------------------------------------------------------
//static void EPD_W21_DisableChargepump(void)
//{
//	EPD_W21_WriteCMD_p1(0x22,0xf0);
//	EPD_W21_WriteCMD(0x20);
//	EPD_W21_WriteCMD(0xff);
//}
//-------------------------------------------------------
//Func	: EPD_W21_Update
//Desc	: 
//Input	:
//Output: 
//Return: 
//Author: 
//Date	: 2011/12/24
//-------------------------------------------------------
static void EPD_W21_Update(void)
{
	EPD_W21_WriteCMD_p1(0x22,0xc7);
	EPD_W21_WriteCMD(0x20);
	ReadBusy();
	EPD_W21_WriteCMD(0xff);
}

static void EPD_W21_Update_Part(void)
{
	EPD_W21_WriteCMD_p1(0x22,0x04);
	//EPD_W21_WriteCMD_p1(0x22,0x08);
	EPD_W21_WriteCMD(0x20);
	ReadBusy();
	EPD_W21_WriteCMD(0xff);
}
//-------------------------------------------------------
//Func	: EPD_W21_WirteLUT(unsigned char *LUTvalue)
//Desc	: write the waveform to the dirver's ram 
//Input	: *LUTvalue, the wavefrom tabe address
//Output: none
//Return: none
//Author: 
//Date	: 2011/12/24
//-------------------------------------------------------
static void EPD_W21_WirteLUT(unsigned char *LUTvalue,unsigned char Size)
{	
	EPD_W21_Write(LUTvalue, Size);
}


void EPD_init_Full(void)
{		
	EPD_W21_Init();			// display
	EPD_W21_WirteLUT((unsigned char *)LUTDefault_full,sizeof(LUTDefault_full));

	EPD_W21_POWERON();
}

void EPD_init_Part(void)
{		
	EPD_W21_Init();			// display
	
	EPD_W21_WirteLUT((unsigned char *)LUTDefault_part,sizeof(LUTDefault_part));
	EPD_W21_POWERON();      		
}

/**********************************************************
²ÎÊý£º Label  
       =1 ÏÔÊ¾ DisBufferÖÐµÄÄÚÈÝ
	   =0 ÏÔÊ¾ DisBufferÖÐµÚÒ»¸ö×Ö½ÚµÄÄÚÈÝ
***********************************************************/

void EPD_Dis_Full(unsigned char *DisBuffer,unsigned char Label)
{
	EPD_W21_SetRamPointer(0x00,(yDot-1)%256,(yDot-1)/256);	// set ram
	if(Label==0)
	{
		EPD_W21_WriteDispRamMono(xDot, yDot, 0xff);	// white	
	}
	else
	{
		EPD_W21_WriteDispRam(xDot, yDot, (unsigned char *)DisBuffer,0);	// white
	}	
	EPD_W21_Update();		
}

/**********************************************************
²ÎÊý£º 
		xStart
			x·½Ïò¿ªÊ¼×ø±ê
		xEnd
			x·½Ïò½áÊø×ø±ê
		yStart
			y·½Ïò¿ªÊ¼×ø±ê
		yEnd
			y·½Ïò½áÊø×ø±ê
		DisBuffer
			ÏÔÊ¾buffer
		Label  
       		=1 ÏÔÊ¾ DisBufferÖÐµÄÄÚÈÝ
	   		=0 ÏÔÊ¾ DisBufferÖÐµÚÒ»¸ö×Ö½ÚµÄÄÚÈÝ
	   
***********************************************************/

void EPD_Dis_Part(unsigned char xStart,unsigned char xEnd,unsigned long yStart,unsigned long yEnd,unsigned char *DisBuffer,unsigned char Label)
{
	if(Label==0)
	{
		part_display(xStart/8,xEnd/8,yEnd%256,yEnd/256,yStart%256,yStart/256);
		EPD_W21_WriteDispRamMono(xEnd-xStart, yEnd-yStart+1, DisBuffer[0]);	// black
 		EPD_W21_Update_Part();
		driver_delay_xms(200);
		part_display(xStart/8,xEnd/8,yEnd%256,yEnd/256,yStart%256,yStart/256);	
		EPD_W21_WriteDispRamMono(xEnd-xStart, yEnd-yStart+1, DisBuffer[0]);	// black
		//driver_delay_xms(200);	
	}
	else
	if(Label==1)
	{
		part_display(xStart/8,xEnd/8,yEnd%256,yEnd/256,yStart%256,yStart/256);	// set ram	
		EPD_W21_WriteDispRam(xEnd-xStart, yEnd-yStart+1,DisBuffer,0);
		EPD_W21_Update_Part();
		//ReadBusy();
		part_display(xStart/8,xEnd/8,yEnd%256,yEnd/256,yStart%256,yStart/256);
		EPD_W21_WriteDispRam(xEnd-xStart, yEnd-yStart+1,DisBuffer,0);
		//EPD_W21_Update();
		EPD_W21_Update_Part();
		//ReadBusy();
	}
	else
	{
		//part_display(xStart/8,xEnd/8,yEnd%256,yEnd/256,yStart%256,yStart/256);	// set ram	
		//EPD_W21_WriteDispRam(xEnd-xStart, yEnd-yStart+1,DisBuffer);
		EPD_W21_Update_Part();
		driver_delay_xms(200);
		part_display(xStart/8,xEnd/8,yEnd%256,yEnd/256,yStart%256,yStart/256);
		EPD_W21_WriteDispRam(xEnd-xStart, yEnd-yStart+1,DisBuffer,0);
		EPD_W21_Update();
		EPD_W21_Update_Part();
		//driver_delay_xms(300);
	}
}

void EPD_Dis_Part1(unsigned char xStart,unsigned char xEnd,unsigned long yStart,unsigned long yEnd,unsigned char *DisBuffer,unsigned char Label)
{
	if(Label==0)
	{
		part_display(xStart/8,xEnd/8,yEnd%256,yEnd/256,yStart%256,yStart/256);
		EPD_W21_WriteDispRamMono(xEnd-xStart, yEnd-yStart+1, DisBuffer[0]);	// black
 		EPD_W21_Update_Part();
		driver_delay_xms(200);
		part_display(xStart/8,xEnd/8,yEnd%256,yEnd/256,yStart%256,yStart/256);	
		EPD_W21_WriteDispRamMono(xEnd-xStart, yEnd-yStart+1, DisBuffer[0]);	// black
		//driver_delay_xms(200);	
	}
	else
	if(Label==1)
	{
		part_display(xStart/8,xEnd/8,yEnd%256,yEnd/256,yStart%256,yStart/256);	// set ram	
		EPD_W21_WriteDispRam(xEnd-xStart, yEnd-yStart+1,DisBuffer,1);
		EPD_W21_Update_Part();
		//ReadBusy();
		part_display(xStart/8,xEnd/8,yEnd%256,yEnd/256,yStart%256,yStart/256);
		EPD_W21_WriteDispRam(xEnd-xStart, yEnd-yStart+1,DisBuffer,1);
		//EPD_W21_Update();
		EPD_W21_Update_Part();
		//ReadBusy();
	}
	else
	{
		//part_display(xStart/8,xEnd/8,yEnd%256,yEnd/256,yStart%256,yStart/256);	// set ram	
		//EPD_W21_WriteDispRam(xEnd-xStart, yEnd-yStart+1,DisBuffer);
		EPD_W21_Update_Part();
		driver_delay_xms(200);
		part_display(xStart/8,xEnd/8,yEnd%256,yEnd/256,yStart%256,yStart/256);
		EPD_W21_WriteDispRam(xEnd-xStart, yEnd-yStart+1,DisBuffer,0);
		EPD_W21_Update();
		EPD_W21_Update_Part();
		//driver_delay_xms(300);
	}
}


/* --------------------------------------------------------------------------*/
/**
 * @Synopsis epd显示屏更新数据 
 *
 * @Param mode  1 更新两个屏  2 更新黑白屏 3 更新黄屏
 * @Param clear 0 不清除另外一个屏幕， 1清除另一个屏幕
 * @Param data1 显存1的现实内容
 * @Param data2 显存2的现实内容
 */
/* ----------------------------------------------------------------------------*/
void epd_show_update(rt_uint8_t mode,rt_uint8_t clear,rt_uint8_t *data1,rt_uint8_t *data2)
{
	//rt_pin_write(LCD_POWR_PIN, 1);
	//epd_power_pin(1);
	EPD_init_Full();//初始化显示屏全屏刷新。
	EPD_Dis_Full(data1, 1);
	EPD_W21_POWEROFF(); //POWER OFF
	EPD_W21_SLEEP(); //SLEEP MODE
	//rt_pin_write(LCD_POWR_PIN, 0);
	//epd_power_pin(0);
}

void epd_show_init(void)
{
	//rt_pin_write(LCD_POWR_PIN, 1);
	//epd_power_pin(1);
	EPD_init_Full();//初始化显示屏全屏刷新。
}

static const char test[] = 
{
	0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE0,0x7F,0xFF,0xFF,
	0xE0,0x7F,0xFF,0xFF,0xE7,0xFF,0xFF,0xFF,0xE7,0xFF,0xF7,0xFF,0xE7,0xFF,0xE7,0xFF,
	0xE7,0xFF,0xC7,0xFF,0xE7,0xFF,0x87,0xFF,0xE7,0xFF,0x07,0xFF,0xE7,0xFE,0x07,0xFF,
	0xE7,0xF8,0x07,0xFF,0xE7,0xF0,0x00,0x07,0xE7,0xE0,0x00,0x07,0xE7,0xC0,0x00,0x07,
	0xE7,0xC0,0x00,0x07,0xE7,0xE0,0x00,0x07,0xE7,0xF0,0x00,0x07,0xE7,0xF8,0x07,0xFF,
	0xE7,0xFC,0x07,0xFF,0xE7,0xFF,0x07,0xFF,0xE7,0xFF,0x87,0xFF,0xE7,0xFF,0xC7,0xFF,
	0xE7,0xFF,0xE7,0xFF,0xE7,0xFF,0xF7,0xFF,0xE7,0xFF,0xFF,0xFF,0xE0,0x7F,0xFF,0xFF,
	0xE0,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*"D:\3232.bmp",0*/
};

static const char batHint[] = 
{
	0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x0F,0xFF,0xFB,0xF0,0x0F,0xDF,0xFF,0xF0,0x0F,0xFF,
	0xF8,0x00,0x00,0x1F,0xF9,0xFF,0xFF,0x9F,0xF9,0xFF,0xFF,0x9F,0xF9,0xFF,0xFF,0x9F,
	0xF9,0xFF,0xFF,0x9F,0xF9,0xFF,0xFF,0x9F,0xF9,0xFF,0xFF,0x9F,0xF9,0xFF,0xFF,0x9F,
	0xF9,0xFF,0xFF,0x9F,0xF9,0xFF,0xFF,0x9F,0xF9,0xFF,0xFF,0x9F,0xF9,0xFF,0xFF,0x9F,
	0xF9,0xFF,0xFF,0x9F,0xF9,0xFF,0xFF,0x9F,0xF9,0xFF,0xFF,0x9F,0xF9,0xFF,0xFF,0x9F,
	0xF9,0xFF,0xFF,0x9F,0xF9,0xFF,0xFF,0x9F,0xF9,0xFF,0xFF,0x9F,0xF9,0xFF,0xFF,0x9F,
	0xF9,0xF0,0x0F,0x9F,0xF9,0xFF,0xFF,0x9F,0xF9,0xFF,0xFF,0x9F,0xF9,0xFF,0xFF,0x9F,
	0xF9,0xFF,0xFF,0x9F,0xF8,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*"D:\test.bmp",0*/
};
	
void epd_update_hint(rt_uint8_t *data)
{
	//epd_power_pin(1);
	//rt_pin_write(LCD_POWR_PIN, 1);
	EPD_init_Part();
	EPD_Dis_Part(0,xDot-1,0,yDot-1,(unsigned char *)data,1); //POWER OFF
	EPD_Dis_Part(xDot-32,xDot-1,yDot-32,yDot-1,(unsigned char *)test,1); //pic
	//EPD_Dis_Part(0,31,0,31,(unsigned char *)test,1); //pic
	//EPD_W21_SLEEP(); //SLEEP MODE
	//rt_pin_write(LCD_POWR_PIN, 0);
}

void epd_module_close(void)
{
	EPD_Dis_Part(xDot-32,xDot-1,yDot-32,yDot-1,(unsigned char *)test,1); //pic
	EPD_W21_SLEEP(); //SLEEP MODE
	//rt_pin_write(LCD_POWR_PIN, 0);
	//epd_power_pin(0);
}

void epd_bat_alarm_hint(rt_uint8_t *data)
{
	EPD_init_Part();
	if(data != RT_NULL)
	{
		EPD_Dis_Part(0,xDot-1,0,yDot-1,(unsigned char *)data,1); 
	}
	EPD_Dis_Part(xDot-32,xDot-1,yDot-32,yDot-1,(unsigned char *)batHint,1); 
}

void epd_update_progress(rt_uint8_t value)
{
	static rt_uint8_t cnt;

	cnt++;
	if(cnt %2 ==0)
	{
		EPD_Dis_Part(xDot-32,xDot-1,yDot-32,yDot-1,(unsigned char *)test,1); //pic
	}
	else
	{
		EPD_Dis_Part1(xDot-32,xDot-1,yDot-32,yDot-1,(unsigned char *)test,1); //pic
	}
	
}


